#pragma once 
#include<iostream>
#include<pthread.h>


namespace Mutex_module
{
    class Mutex
    {
    public:
        Mutex()
        {
            pthread_mutex_init(&_mutex,nullptr);
        }
        void Lock()
        {
            pthread_mutex_lock(&_mutex);
        }
        void Unlock()
        {
            pthread_mutex_unlock(&_mutex);
        }
        pthread_mutex_t Get() { return _mutex ;}
        ~Mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
    private:
        pthread_mutex_t _mutex;
    };

    class LockGuard
    {
    public:
        LockGuard(Mutex mut)
        :_mut(mut)
        {
            _mut.Lock();
        }
        ~LockGuard()
        {
            _mut.Unlock();
        }
    private:
        Mutex _mut;
    };
}

